/***
 *  表单数据收集
 *  受控组件
 *  表单元素的值通过state进行控制管理
 *
 *
 */
import React, { Component } from 'react'

export default class App extends Component {
  state = {
    username: '',
    password: ''
  }
  render() {
    return (
      <div>
        <div>
          <input
            type="text"
            placeholder="用户名"
            value={this.state.username}
            onChange={(event) =>
              this.setState({ username: event.target.value })
            }
          />
        </div>
        <div>
          <input
            type="password"
            placeholder="密码"
            value={this.state.password}
            onChange={(e) => this.setState({ password: e.target.value })}
          />
        </div>
        <div>
          <button onClick={this.submit}>登录</button>
        </div>
      </div>
    )
  }
  submit = ()=>{
    console.log(this.state);
  }
}
